//
//  UIImageView+Kingfisher.swift
//  
//
//  Created by tangbl93 on 2021/1/5.
//

import UIKit

#if canImport(Kingfisher)
import Kingfisher

public extension UIImageView {

    ///  Sets an image to the image view with a url
    func yx_network(with imageUrl: String?, placeholder: Placeholder? = nil,
                        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) {
        guard let imageUrl = imageUrl else { return }
        
        let options:KingfisherOptionsInfo = [.transition(.fade(0.6))]
        let networkUrl = imageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? imageUrl
        self.kf.setImage(with: URL(string: networkUrl), placeholder: placeholder, options: options, completionHandler: completionHandler)
    }
}
#endif
